﻿Imports Library

Module DailyTask

    Sub Main()

        ' 1.Check month summary for each account, if not exist then create
        If Not MonthlySummary.IsExistSummaryRecordThisMonth() Then
            For Each value As String In "IA,VINCENT,NICOLE".Split(",")
                Dim summary As MonthlySummary = New MonthlySummary()
                summary.Owner = value
                summary.Month = Now.ToString("yyyy-MM")
                summary.Spend = 0
                summary.Income = 0
                summary.Remark = ""
                summary.ModifyBy = "system"
                summary.Create()
            Next
        End If

        ' 2. Check each task, if suitable then add add record
        Dim taskList As List(Of ScheduleTask) = ScheduleTask.FindAll().ToList.FindAll(Function(item) item.EndDate > Now)

        For Each item As ScheduleTask In taskList

            Dim tempBaseRecords As Transaction = New Transaction
            If item.Period = "DAILY" Then
                If Now.DayOfWeek <> DayOfWeek.Saturday And Now.DayOfWeek <> DayOfWeek.Sunday Then
                    tempBaseRecords.RecordDate = Now.ToString("yyyy-MM-dd")
                    tempBaseRecords.Owner = item.Owner
                    tempBaseRecords.Payer = item.Owner
                    tempBaseRecords.Name = item.RecordType
                    tempBaseRecords.RecordType = "支出"
                    tempBaseRecords.Amount = item.Amount
                    tempBaseRecords.Remark = item.Remark
                    tempBaseRecords.Create()
                End If
            ElseIf item.Period = "MONTHLY" And Now.Day = 1 Then
                tempBaseRecords.RecordDate = Now.ToString("yyyy-MM-dd")
                tempBaseRecords.Owner = item.Owner
                tempBaseRecords.Payer = item.Owner
                tempBaseRecords.Name = item.RecordType
                tempBaseRecords.RecordType = "支出"
                tempBaseRecords.Amount = item.Amount
                tempBaseRecords.Remark = item.Remark
                tempBaseRecords.Create()
            End If

        Next
    End Sub

End Module
